package com.mi.soul.windows;

import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.ptr.IntByReference;

/**
 * 王永吉
 */
public class Start {

    private static final Kernel32 KERNEL = Kernel32.INSTANCE;

    private static final User32 USER = User32.INSTANCE;

    public static void main(String[] args) {
        WinDef.HWND hwnd = USER.FindWindow("Notepad", "aaaa.txt - 记事本");
//        WinDef.HWND hwnd = USER.FindWindow("WTWindow", null);
        Pointer pointer = hwnd.getPointer();


        IntByReference pidReference = new IntByReference();
        int i = USER.GetWindowThreadProcessId(hwnd, pidReference);
        int pid = pidReference.getValue();
//        return KERNEL.OpenProcess(WinNT.PROCESS_ALL_ACCESS, false, pid);
//        WinNT.HANDLE handleByWindowName = WindowsUtils.getHandleByWindowName();
        System.out.println(i);
        System.out.println(hwnd);
        System.out.println(pidReference);

        System.out.println(hwnd.hashCode());//句柄ID
        System.out.println(pointer.hashCode());//句柄ID
        System.out.println(pid);
//        System.out.println(handleByWindowName);
    }

}
